package com.java;

import java.util.concurrent.CountDownLatch;

/**
 * 6个学生上自习，要等到人都走完，班长拿钥匙关教室门
 * Count 计数
 * Down 向下
 * Latch 门闩
 * @author jingjintao
 * @date 2021/10/24 - 22:17
 **/
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+"\t走人");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"\t拿钥匙关门");
    }
}
